package com.mbc.service.impl;


import com.mbc.dto.CommentSectionDTO;
import com.mbc.mapper.CommentSectionMapper;
import com.mbc.service.CommentSectionService;
import com.mbc.vo.CommentSectionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;


/**
 * <p>
 * 评论区表 服务实现类
 * </p>
 *
 * @author suimeng
 * @since 2024-04-21
 */
@Service
@Transactional
public class CommentSectionServiceImpl implements CommentSectionService {


    @Autowired
    private CommentSectionMapper commentSectionMapper;

    /**
     * 根据活动id新增评论
     *
     * @param activityId        活动 ID
     * @param userId            用户 ID
     * @param commentSectionDTO 评论部分 DTO
     * @return boolean
     */
    @Override
    public boolean insertComment(Integer activityId, Integer userId, CommentSectionDTO commentSectionDTO) {
        LocalDateTime now = LocalDateTime.now();
        return commentSectionMapper.insertComment(activityId, userId, commentSectionDTO, now) > 0;
    }

    /**
     * 获取评论区内容
     *
     * @param activityId 活动 ID
     * @param page       页
     * @param size       大小
     * @return {@link ArrayList}<{@link CommentSectionVO}>
     */
    @Override
    public ArrayList<CommentSectionVO> getComment(Integer activityId, Integer page, Integer size) {
        Integer offest = (page - 1) * size;
        return commentSectionMapper.getComment(activityId, offest, size);
    }

}
